package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.system.service.IComplainttypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Complainttype;

import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 投诉类型 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/complainttype")
public class ComplainttypeController extends BaseController
{
    private String prefix = "system/complainttype";
	
	@Autowired
	private IComplainttypeService complainttypeService;
	
	@RequiresPermissions("system:complainttype:view")
	@GetMapping()
	public String complainttype()
	{
	    return prefix + "/complainttype";
	}
	
	/**
	 * 查询投诉类型列表
	 */
	@RequiresPermissions("system:complainttype:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Complainttype complainttype)
	{
		startPage();
        List<Complainttype> list = complainttypeService.selectComplainttypeList(complainttype);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出投诉类型列表
	 */
	@RequiresPermissions("system:complainttype:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Complainttype complainttype)
    {
    	List<Complainttype> list = complainttypeService.selectComplainttypeList(complainttype);
        ExcelUtil<Complainttype> util = new ExcelUtil<Complainttype>(Complainttype.class);
        return util.exportExcel(list, "complainttype");
    }
	
	/**
	 * 新增投诉类型
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存投诉类型
	 */
	@RequiresPermissions("system:complainttype:add")
	@Log(title = "投诉类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Complainttype complainttype)
	{		
		return toAjax(complainttypeService.insertComplainttype(complainttype));
	}

	/**
	 * 修改投诉类型
	 */
	@GetMapping("/edit/{complainttypeId}")
	public String edit(@PathVariable("complainttypeId") Integer complainttypeId, ModelMap mmap)
	{
		Complainttype complainttype = complainttypeService.selectComplainttypeById(complainttypeId);
		mmap.put("complainttype", complainttype);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存投诉类型
	 */
	@RequiresPermissions("system:complainttype:edit")
	@Log(title = "投诉类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Complainttype complainttype)
	{		
		return toAjax(complainttypeService.updateComplainttype(complainttype));
	}
	
	/**
	 * 删除投诉类型
	 */
	@RequiresPermissions("system:complainttype:remove")
	@Log(title = "投诉类型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(complainttypeService.deleteComplainttypeByIds(ids));
	}
	
}
